#include <bstree.h>
#include <time.h>

void f()
{
    BST<int> iBsTree;

    srand(time(NULL));

    int v[5];
    for (int i = 0; i < 5; i ++)
    {
        v[i] = rand() % 100;
        cout << "insert " << v[i] << endl;
        iBsTree.insert(v[i]);
    }
    cout << iBsTree << endl;

#if 0
    for (BstNode<int> *piNode = iBsTree.minimum(); piNode; piNode = iBsTree.successor(piNode))
    {
        cout << *piNode;
    }
    cout << endl;

    for (BstNode<int> *piNode = iBsTree.maximum(); piNode; piNode = iBsTree.predecessor(piNode))
    {
        cout << *piNode;
    }
    cout << endl;
#endif

#if 1
    for (int i = 0, index = rand() % 5; i < 5; i++, index = (index+1) % 5)
    {
        cout << "remove " << v[index] << endl;
        iBsTree.remove(v[index]);
        cout << iBsTree << endl;
    }
    cout << "after deletion: " << iBsTree << endl;
#endif

#if 0
    BST<int> iBsTree1;
    for (int i = 0; i < 5; i ++)
    {
        cout << "insert " << v[i] << endl;
        iBsTree1.insert(v[i]);
    }
    cout << iBsTree1 << endl;

    iBsTree.remove(v[2]);
    iBsTree.remove(v[4]);
    cout << iBsTree << endl;

    iBsTree1.remove(v[4]);
    iBsTree1.remove(v[2]);
    cout << iBsTree1 << endl;
#endif
}

int
main()
{
    f();
}
